package com.esri.core.tasks.na;

import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.e;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.CallbackListener;
import com.esri.core.map.Graphic;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;

/* loaded from: classes.dex */
public abstract class RouteTask {
    public void dispose() {
    }

    public abstract NetworkDescription getNetworkDescription() throws Exception;

    public abstract RouteParameters retrieveDefaultRouteTaskParameters() throws Exception;

    public abstract RouteResult solve(RouteParameters routeParameters) throws Exception;

    public static RouteTask createOnlineRouteTask(String str, UserCredentials userCredentials) throws Exception {
        return new OnlineRouteTask(str, userCredentials);
    }

    public static RouteTask createLocalRouteTask(String str, String str2) throws Exception {
        return new LocalRouteTask(str, str2);
    }

    public Future<RouteResult> solve(final RouteParameters routeParameters, final CallbackListener<RouteResult> callbackListener) {
        return (this instanceof LocalRouteTask ? e.d : e.c).submit(new Callable<RouteResult>() { // from class: com.esri.core.tasks.na.RouteTask.1
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // java.util.concurrent.Callable
            public RouteResult call() {
                RouteResult routeResult = null;
                try {
                    routeResult = RouteTask.this.solve(routeParameters);
                } catch (Exception e) {
                    CallbackListener callbackListener2 = callbackListener;
                    if (callbackListener2 != null) {
                        callbackListener2.onError(e);
                    }
                }
                if (Thread.currentThread().isInterrupted()) {
                    return routeResult;
                }
                CallbackListener callbackListener3 = callbackListener;
                if (callbackListener3 != null) {
                    callbackListener3.onCallback(routeResult);
                }
                return routeResult;
            }
        });
    }

    Route solve(List<Graphic> list, SpatialReference spatialReference) throws Exception {
        RouteParameters retrieveDefaultRouteTaskParameters = retrieveDefaultRouteTaskParameters();
        NAFeaturesAsFeature nAFeaturesAsFeature = new NAFeaturesAsFeature(list);
        if (spatialReference != null) {
            nAFeaturesAsFeature.setSpatialReference(spatialReference);
            retrieveDefaultRouteTaskParameters.setOutSpatialReference(spatialReference);
        }
        retrieveDefaultRouteTaskParameters.setStops(nAFeaturesAsFeature);
        retrieveDefaultRouteTaskParameters.setReturnStops(false);
        retrieveDefaultRouteTaskParameters.setReturnPointBarriers(false);
        retrieveDefaultRouteTaskParameters.setReturnPolygonBarriers(false);
        retrieveDefaultRouteTaskParameters.setReturnPolylineBarriers(false);
        retrieveDefaultRouteTaskParameters.setReturnRoutes(true);
        retrieveDefaultRouteTaskParameters.setReturnDirections(true);
        List<Route> routes = solve(retrieveDefaultRouteTaskParameters).getRoutes();
        if (routes.size() > 0) {
            return routes.get(0);
        }
        return null;
    }

    Future<Route> solve(final List<Graphic> list, final SpatialReference spatialReference, final CallbackListener<Route> callbackListener) {
        return (this instanceof LocalRouteTask ? e.d : e.c).submit(new Callable<Route>() { // from class: com.esri.core.tasks.na.RouteTask.2
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // java.util.concurrent.Callable
            public Route call() {
                Route route = null;
                try {
                    route = RouteTask.this.solve(list, spatialReference);
                } catch (Exception e) {
                    CallbackListener callbackListener2 = callbackListener;
                    if (callbackListener2 != null) {
                        callbackListener2.onError(e);
                    }
                }
                if (Thread.currentThread().isInterrupted()) {
                    return route;
                }
                CallbackListener callbackListener3 = callbackListener;
                if (callbackListener3 != null) {
                    callbackListener3.onCallback(route);
                }
                return route;
            }
        });
    }

    Route solve(Point point, Point point2, SpatialReference spatialReference) throws Exception {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new StopGraphic(point));
        arrayList.add(new StopGraphic(point2));
        return solve(arrayList, spatialReference);
    }

    Future<Route> solve(Point point, Point point2, SpatialReference spatialReference, CallbackListener<Route> callbackListener) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new StopGraphic(point));
        arrayList.add(new StopGraphic(point2));
        return solve(arrayList, spatialReference, callbackListener);
    }

    Route solve(double d, double d2, double d3, double d4) throws Exception {
        return solve(new Point(d2, d), new Point(d4, d3), SpatialReference.create(SpatialReference.WKID_WGS84));
    }

    Future<Route> solve(double d, double d2, double d3, double d4, CallbackListener<Route> callbackListener) {
        return solve(new Point(d2, d), new Point(d4, d3), SpatialReference.create(SpatialReference.WKID_WGS84), callbackListener);
    }
}
